package com.xzp.bams.entity;

/**
 * @TODO
 * @Author xu
 * 2025/3/10
 */
public class LoanSavingAccount extends SavingAccount implements Loanable {
    private long loanAmount;

    public LoanSavingAccount() {
    }

    public LoanSavingAccount(Long id, String password, String name, String personId, String email, double balance, long loanAmount) {
        super(id, password, name, personId, email, balance);
        this.loanAmount = loanAmount;
    }


    /**
     * 贷款
     *
     * @param money
     * @return
     */
    @Override
    public Account requestLoan(double money) {
        if (money > 0) {
            this.loanAmount += money;
            this.setBalance(this.getBalance() + money);
        } else {
            System.out.println("贷款额度>0");
        }
        //this 当前正在使用的对象
        return this;
    }

    /**
     * 还款
     *
     * @param money
     * @return
     */
    @Override
    public Account payLoan(double money) {
        if (money > 0) {
            if (money <= loanAmount) {
                if (this.getBalance() >= money) {
                    this.loanAmount -= money;
                    this.setBalance(this.getBalance() - money);
                } else {
                    System.out.println("您的账户余额不够支付还款操作！");
                }
            } else {
                System.out.println("还款金额<=贷款金额，");
            }
        } else {
            System.out.println("还款额度>0");
        }
        return this;

        /*if (money > 0) {
            if (money <= loanAmount) {
                if (this.getBalance() >= money) {
                    this.loanAmount -= money;
                    this.setBalance(this.getBalance() - money);
                } else {
                    System.out.println("您的账户余额不够支付还款操作！");
                }
            } else {
                System.out.println("太笨了，还款金额<=贷款金额，你咋还多了呢");
            }
        } else {
            System.out.println("还款额度>0");
        }
        return this;
        */
    }


    /**
     * 获取
     * @return loanAmount
     */
    public long getLoanAmount() {
        return loanAmount;
    }

    /**
     * 设置
     * @param loanAmount
     */
    public void setLoanAmount(long loanAmount) {
        this.loanAmount = loanAmount;
    }

    public String toString() {
        return "LoanSavingAccount{loanAmount = " + loanAmount + "}";
    }
}

